package com.example.controller.question;

import com.example.domain.question.dto.QuestionAddDTO;
import com.example.domain.question.dto.QuestionEditDTO;
import com.example.domain.question.dto.QuestionQueryDTO;
import com.example.domain.question.vo.QuestionDetailVO;
import com.example.server.question.IQuestionServer;
import oj.common.core.controller.BaseController;
import oj.common.core.domain.Result;
import oj.common.core.domain.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {
    @Autowired
    private IQuestionServer questionServer;

    @GetMapping("/list")
    //参数应该是一个dto
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        //首先接收的参数有页数，一页显示的数据多少，这里还根据题目进行模糊搜索，还有困难程度
        return getTableDataInfo(questionServer.selectList(questionQueryDTO));
    }
    //在这里增加添加，详情，删除的接口

    @PostMapping("/add")
    public Result<Void> add(@RequestBody QuestionAddDTO questionAddDTO) {
        return toResult(questionServer.add(questionAddDTO));
    }

    //详情的接口
    @GetMapping("/detail")
    public Result<QuestionDetailVO> detail(Long questionId){
        return Result.success(questionServer.detail(questionId));
    }
    //编辑的接口,然后进行更新
    @PutMapping("/edit")
    public Result<Void> update(@RequestBody QuestionEditDTO questionEditDTO){
        return toResult(questionServer.update(questionEditDTO));
    }

    //删除的接口
    @DeleteMapping("/delete")
    public Result<Void> delete(Long questionId) {
        return toResult(questionServer.delete(questionId));
    }
}
